import Vue from 'vue'
import Router from 'vue-router'
import index from '@/components/index'
import cart from '@/components/cart'
import item from '@/components/item'
import detail from '@/components/detail'
import mytest from '@/components/mytest'

import test from '@/components/test'
import cart_test from '@/components/cart_test'

import register from '@/components/register'
import login from '@/components/login'
import myprofile from '@/components/myprofile'

import register_week from '@/components/register_week'
import login_week from '@/components/login_week'

import mypics from '@/components/mypics'
import update_pics from '@/components/update_pics'

import insertgoods from '@/components/insertgoods'
import editgood from '@/components/editgood'

import search from '@/components/search'


Vue.use(Router)

var routes = [
        {
          path:'/',
          name:'index',
          component:index
        },
        {
          path:'/cart',
          name:'cart',
          component:cart
        },
        {
          path:'/item',
          name:'item',
          component:item
        },
        {
          path:'/detail',
          name:'detail',
          component:detail
        },
        {
          path:'/mytest',
          name:'mytest',
          component:mytest
        },

        {
          path:'/test',
          name:'test',
          component:test
        },
        {
          path:'/cart_test',
          name:'cart_test',
          component:cart_test
        },

        //注册页面
        {
          path:'/register',
          name:'register',
          component:register
        },
        //登录页面
        {
          path:'/login',
          name:'login',
          component:login
        },
        //个人中心页面
        {
          path:'/myprofile',
          name:'myprofile',
          component:myprofile,
          //拦截器的使用
          beforeEnter: (to, from, next) => {
            // 判断是否有username(用户是否登录)
            if(localStorage.getItem('username')){
              
              // console.log('已登录')

              next();

            }else{
              // console.log('未登录')

              next('/login');

            }
          },

        },

        //活动(幻灯片接口)
        {
          path:'/mypics',
          name:'mypics',
          component:mypics
        },
        //修改幻灯片页面
        {
          path:'/update_pics',
          name:'update_pics',
          component:update_pics
        },

        //商品表
        {
          path:'/insertgoods',
          name:'insertgoods',
          component:insertgoods
        },

        //修改商品
        {
          path:'/editgood',
          name:'editgood',
          component:editgood
        },

        //商品检索
        {
          path:'/search',
          name:'search',
          component:search
        },


//考试接口
        {
          path:'/register_week',
          name:'register_week',
          component:register_week
        },

        {
          path:'/login_week',
          name:'login_week',
          component:login_week
        },

]

export default new Router({
  routes:routes,
  mode:'history'   /*hash*/
})
